package pong.app.factories
{
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.errors.IllegalOperationError;
	
	import pong.app.IPongAppSkin;
	import pong.app.IPongAppSkinFactory;
	import pong.app.utilities.PongAppSkin;
	
	public class PongAppSkinFactory implements IPongAppSkinFactory
	{
		
		public static const LOADING_STATE:String = "assets.LoadingState";
		
		public static const MENU_STATE:String = "assets.MenuState";
		
		public static const INSTRUCTIONS_STATE:String = "assets.InstructionsState";
		
		public static const LOGIN_STATE:String = "assets.LoginState";
		
		public static const PLAYING_STATE:String = "assets.PlayingState";
		
		public static const SAVING_STATE:String = "assets.SavingState";
		
		public static const SCORES_STATE:String = "assets.ScoresState";
		
		
		[Embed(source="../assets/pongfu-assets.swf", symbol="assets.LoadingState")]
		private const LOADING_STATE_CLASS:Class;
		
		[Embed(source="../assets/pongfu-assets.swf", symbol="assets.MenuState")]
		private const MENU_STATE_CLASS:Class;
		
		[Embed(source="../assets/pongfu-assets.swf", symbol="assets.InstructionsState")]
		private const INSTRUCTIONS_STATE_CLASS:Class;
		
		//[Embed(source="../assets/pongfu-assets.swf", symbol="assets.LoginState")]
		//private const LOGIN_STATE_CLASS:Class;
		
		[Embed(source="../assets/pongfu-assets.swf", symbol="assets.PlayingState")]
		private const PLAYING_STATE_CLASS:Class;
		
		[Embed(source="../assets/pongfu-assets.swf", symbol="assets.SavingState")]
		private const SAVING_STATE_CLASS:Class;
		
		[Embed(source="../assets/pongfu-assets.swf", symbol="assets.ScoresState")]
		private const SCORES_STATE_CLASS:Class;
		
		
		public function PongAppSkinFactory()
		{
		}
		
		
		public function createSkin(name:String):IPongAppSkin
		{
			switch (name)
			{
				case LOADING_STATE:
					return this.createInstance(this.LOADING_STATE_CLASS);
					
				case MENU_STATE:
					return this.createInstance(this.MENU_STATE_CLASS);
					
				case INSTRUCTIONS_STATE:
					return this.createInstance(this.INSTRUCTIONS_STATE_CLASS);
					
				//case LOGIN_STATE:
				//	return this.createInstance(this.LOGIN_STATE_CLASS);
					
				case PLAYING_STATE:
					return this.createInstance(this.PLAYING_STATE_CLASS);
					
				case SAVING_STATE:
					return this.createInstance(this.SAVING_STATE_CLASS);
					
				case SCORES_STATE:
					return this.createInstance(this.SCORES_STATE_CLASS);
					
				default:
					throw new Error("Unknown skin " + name);
			}
		}
		
		
		
		
		private function createInstance(c:Class):IPongAppSkin
		{
			var displayObjectContainer:DisplayObjectContainer = new c();
			
			var appSkin:IPongAppSkin = new PongAppSkin(displayObjectContainer);
			
			return appSkin;
		}
		
		
	}
}